package com.yunquan.ohana.ui.history.status

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.yunquan.ohana.BR
import com.yunquan.ohana.R
import com.yunquan.ohana.base.ui.BaseActivity
import com.yunquan.ohana.databinding.ActivityStatusBinding
import com.yunquan.ohana.ui.history.status.adapter.StatusAdapter
import com.yunquan.ohana.ui.history.status.decoration.StatusDecoration

class StatusActivity : BaseActivity<ActivityStatusBinding, StatusViewModel>() {

    private var mAdapter: StatusAdapter? = null

    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_status
    }

    override fun initVariableId(): Int {
        return BR.statusViewModel
    }

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        val bundle = intent.extras
        bundle?.let {
            viewModel!!.groupUid = it.getString("groupUid")
            viewModel!!.getFramesData()
        }
        binding!!.rvContent.layoutManager = LinearLayoutManager(this)
        binding!!.rvContent.addItemDecoration(StatusDecoration(this))
        mAdapter = StatusAdapter(viewModel!!.mData)
        binding!!.rvContent.adapter = mAdapter
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel!!.ui.observe(this) {
            when (it) {
                0 -> {
                    mAdapter?.notifyDataSetChanged()
                }
            }
        }
    }

}